<?php

use think\migration\Migrator;
use think\migration\db\Column;
use Phinx\Db\Adapter\MysqlAdapter;

class OperLog extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $exists = $this->hasTable('oper_log');
        if(!$exists){
        $table = $this->table('oper_log', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '后台操作日志表' ,'id' => 'id' ,'primary_key' => ['id']]);
        $table->addColumn('account', 'string', ['limit' => 160,'null' => false,'default' => '','signed' => true,'comment' => '账号',])
			->addColumn('method', 'string', ['limit' => 150,'null' => false,'default' => null,'signed' => true,'comment' => '方法',])
			->addColumn('router', 'string', ['limit' => 500,'null' => false,'default' => '','signed' => true,'comment' => '路由',])
			->addColumn('ip', 'string', ['limit' => 100,'null' => false,'default' => '','signed' => true,'comment' => 'ip',])
			->addColumn('ip_location', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'ip归属地',])
			->addColumn('request_data', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => true,'signed' => true,'comment' => '请求数据',])
			->addColumn('response_code', 'string', ['limit' => 20,'null' => true,'signed' => true,'comment' => '响应状态码',])
			->addColumn('response_data', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => true,'signed' => true,'comment' => '响应数据',])
			->addColumn('create_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '创建时间',])
			->addColumn('update_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '更新时间',])
            ->create();
        }
    }
}
